package com.taichuan.selfcheck.hardware.mcuUpdate;

import android.content.Context;

import com.taichuan.serialcommunication.mcuUpdate.base.BaseMcuUpdateClient;
import com.taichuan.tcutils.taichuan.SystemUtils;
import com.taichuan.tcutils.taichuan.TcDeviceType;

/**
 * 该类主要用于
 *
 * @author CamelLuo
 * @version 2020/2/18
 */
public class McuUpdateManager {
    private BaseMcuUpdateClient mcuUpdateClient = null;

    private static final class SingletonHolder {
        private final static McuUpdateManager instance = new McuUpdateManager();
    }

    public static McuUpdateManager get() {
        return McuUpdateManager.SingletonHolder.instance;
    }

    public void init(Context context){
        //根据条件决定初始化哪个单片机程序升级实体类
        if (SystemUtils.isSupportMcuUpdate()){
            if (SystemUtils.getTcDeviceType() == TcDeviceType.L10_Pro){
//            mcuUpdateClient = new L10ProMcuUpdateClient(context);
            }else if (SystemUtils.getTcDeviceType() == TcDeviceType.A64_VERTICAL_TOUCH ||
                    SystemUtils.getTcDeviceType() == TcDeviceType.A64_VERTICAL_TOUCH_HZ01 ||
                    SystemUtils.getTcDeviceType() == TcDeviceType.A64_VERTICAL_KEY){
//                mcuUpdateClient = new A64VerticalTouchMcuUpdateClient(context);
            }else if (SystemUtils.getTcDeviceType() == TcDeviceType.RK3399_LANDSCAPE_KEY ||
                    SystemUtils.getTcDeviceType() == TcDeviceType.RK3399_VERTICAL_TOUCH  ||
                    SystemUtils.getTcDeviceType() == TcDeviceType.RK3399_VERTICAL_TOUCH_TEMP_DOOR){
//                mcuUpdateClient = new Rk3399LandKeyMcuUpdateClient(context);
            }else if (SystemUtils.getTcDeviceType() == TcDeviceType.RK3399_VANKE_SITE_BOX){
                mcuUpdateClient = new VankeSiteBoxMcuUpdateClient(context);
            }
        }
    }

    public void main(BaseMcuUpdateClient.OnMcuUpdateStateListener stateListener){
        //如果BaseMcuUpdateClient 不为null，则执行
        if (mcuUpdateClient != null){
            mcuUpdateClient.main(stateListener);
        }
    }

    public BaseMcuUpdateClient.McuUpdateState getMcuUpdateState(){
        if (mcuUpdateClient != null){
            return mcuUpdateClient.getUpdateState();
        }else {
            return BaseMcuUpdateClient.McuUpdateState.STATE_INIT;
        }
    }

    public BaseMcuUpdateClient getMcuUpdateClient() {
        return mcuUpdateClient;
    }
}
